package com.qd.thirdpart.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cdqidi.constant.ConstantDto;
import com.cdqidi.db.BaseService;
import com.cdqidi.dto.CacheKey;
import com.cdqidi.dto.GeoPointDTO;
import com.cdqidi.exception.ApiException;
import com.cdqidi.util.GeoUtil;
import com.cdqidi.util.RedisTemplateUtil;
import com.qd.common.panda.constant.PandaConstant;
import com.qd.common.panda.domain.entity.carpark.CarParkDTO;
import com.qd.common.panda.domain.entity.carpark.CarParkFeeDTO;
import com.qd.common.panda.domain.entity.carpark.CarParkLocationDTO;
import com.qd.common.panda.domain.entity.carpark.CarParkTimeDTO;
import com.qd.common.panda.domain.enums.CarParkBillRuleEnum;
import com.qd.common.sys.constant.Constants;
import com.qd.panda.service.park.*;
import com.qd.system.service.dict.MbUtil;
import com.qd.thirdpart.domain.ThirdJtParkSyncDTO;
import com.qd.thirdpart.mapper.ThirdJtParkSyncMapper;
import com.qd.thirdpart.model.ThirdJtParkSync;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

import static java.util.stream.Collectors.toList;

/**
 * 交投停车场同步
 *
 * @author sjk
 */
@RequiredArgsConstructor
@Service
@Slf4j
public class ThirdJtParkSyncService extends BaseService<ThirdJtParkSyncMapper, ThirdJtParkSync> {

    private static final String PREFIX_ID = "third_jt_park_sync_parkNo_{0}";

    private final RedisTemplateUtil<ThirdJtParkSync> redisTemplateUtil;

    private final CarParkService carParkService;
    private final ParkHolderService parkHolderService;

    private final CarParkFeeService carParkFeeService;
    private final CarParkTimeService carParkTimeService;

    private final CarParkLocationService carParkLocationService;

//    private final TencentLocationService tencentLocationService;


    public void saveOrUpdateThirdJtParkToCarPark(ThirdJtParkSyncDTO thirdJtParkSyncDTO) {
        CarParkDTO carParkDTO = carParkService.getByIdDto(thirdJtParkSyncDTO.getParkNo());
        if (null == carParkDTO) {
            carParkDTO = new CarParkDTO();
            carParkDTO.setPId(thirdJtParkSyncDTO.getParkNo());
            carParkDTO.setName(thirdJtParkSyncDTO.getName());
            carParkDTO.setParkNum(thirdJtParkSyncDTO.getTotal());
            carParkDTO.setIntoFreeTime(15);
            carParkDTO.setPayFreeTime(0);
            //交投
            carParkDTO.setCarParkType(PandaConstant.CAR_PARK_TYPE_1);
            carParkDTO.setAddTime(LocalDateTime.now());
            carParkDTO.setThirdPartyBill(ConstantDto.SF1);
            carParkDTO.setConfirmIn(ConstantDto.SF0);
            carParkDTO.setConfirmOut(ConstantDto.SF0);
            carParkDTO.setOperator(Constants.ADMIN_DEFAULT_ID);
            carParkDTO.setOrgId(Constants.DEFAULT_TREE_PARENT_ID);
            carParkDTO.setEnable(ConstantDto.SF1);
            carParkDTO.setParkType(PandaConstant.PARK_TYPE_CAR_PARK);
            carParkDTO.setOwnBusiness(ConstantDto.SF0);
            carParkDTO.setOnStreet(ConstantDto.SF1);
            carParkDTO.setParkSpaceType(PandaConstant.PARK_SPACE_TYPE2);
            carParkDTO.setEtcPay(ConstantDto.SF0);

            CarParkLocationDTO location = new CarParkLocationDTO();
            location.setPId(carParkDTO.getPId());
            location.setAddress(thirdJtParkSyncDTO.getAddress());
            location.setLat(thirdJtParkSyncDTO.getConvertLat());
            location.setLng(thirdJtParkSyncDTO.getConvertLng());
            location.setLocationType(5);
            carParkDTO.setLocation(location);

            CarParkTimeDTO carParkTimeDTO = new CarParkTimeDTO();
            carParkTimeDTO.setPId(carParkDTO.getPId());
            carParkTimeDTO.setStartTime(thirdJtParkSyncDTO.getServiceStart());
            carParkTimeDTO.setEndTime(thirdJtParkSyncDTO.getServiceEnd());
            carParkDTO.setTime(carParkTimeDTO);

            String billRule = getBillRule(thirdJtParkSyncDTO);
            if (StringUtils.hasLength(billRule)) {
                CarParkFeeDTO carParkFee = new CarParkFeeDTO();
                carParkFee.setPId(carParkDTO.getPId());
                carParkFee.setBillRule(billRule);
                carParkFee.setNote(MbUtil.idToRemark("JT_" + thirdJtParkSyncDTO.getFeeRuleId()));
                carParkDTO.setFee(carParkFee);
            } else {
                //不知道的计费规则，不处理
                return;
            }
            parkHolderService.save(carParkDTO, false);
            carParkDTO.freeData();
        } else {
            Optional.ofNullable(carParkService.getByIdDto(thirdJtParkSyncDTO.getParkNo())).ifPresent(newCarParkDTO -> {
                boolean isUpdate = false;
                if (!newCarParkDTO.getName().equals(thirdJtParkSyncDTO.getName())) {
                    isUpdate = true;
                    newCarParkDTO.setName(thirdJtParkSyncDTO.getName());
                }
                if (!newCarParkDTO.getParkNum().equals(thirdJtParkSyncDTO.getTotal())) {
                    isUpdate = true;
                    newCarParkDTO.setParkNum(thirdJtParkSyncDTO.getTotal());
                }
                if (isUpdate) {
                    carParkService.update(newCarParkDTO);
                    newCarParkDTO.freeData();
                }
            });
            Optional.ofNullable(carParkFeeService.getUniqueByPId(thirdJtParkSyncDTO.getParkNo())).ifPresent(carParkFee -> {
                String billRule = getBillRule(thirdJtParkSyncDTO);
                if (!carParkFee.getBillRule().equals(billRule)) {
                    carParkFee.setBillRule(billRule);
                    carParkFee.setNote(MbUtil.idToRemark("JT_" + thirdJtParkSyncDTO.getFeeRuleId()));
                    carParkFeeService.update(carParkFeeService.modelToDto(carParkFee));
                    carParkFee.freeData();
                }
            });

            Optional.ofNullable(carParkTimeService.getUniqueByPId(thirdJtParkSyncDTO.getParkNo())).ifPresent(carParkTime -> {
                boolean isUpdate = false;
                final CarParkTimeDTO dto = carParkTimeService.modelToDto(carParkTime);
                if (!dto.getStartTime().equals(thirdJtParkSyncDTO.getServiceStart())) {
                    isUpdate = true;
                    dto.setStartTime(thirdJtParkSyncDTO.getServiceStart());
                }
                if (!dto.getEndTime().equals(thirdJtParkSyncDTO.getServiceEnd())) {
                    isUpdate = true;
                    dto.setEndTime(thirdJtParkSyncDTO.getServiceEnd());
                }
                if (isUpdate) {
                    carParkTimeService.update(dto);
                    dto.freeData();
                    carParkTime.freeData();
                }
            });
            buildLocation(thirdJtParkSyncDTO, carParkDTO);
        }
    }

    private void buildLocation(ThirdJtParkSyncDTO thirdJtParkSyncDTO, CarParkDTO carParkDTO) {
        CarParkLocationDTO carParkLocationDTO = carParkLocationService.getByIdDto(thirdJtParkSyncDTO.getParkNo());
        if(null ==carParkLocationDTO){
            carParkLocationDTO = new CarParkLocationDTO();
            carParkLocationDTO.setPId(carParkDTO.getPId());
            carParkLocationDTO.setAddress(thirdJtParkSyncDTO.getAddress());
            carParkLocationDTO.setLat(thirdJtParkSyncDTO.getConvertLat());
            carParkLocationDTO.setLng(thirdJtParkSyncDTO.getConvertLng());
            carParkLocationDTO.setLocationType(5);
            carParkLocationService.save(carParkLocationDTO);
        }else{
            boolean isUpdate = false;
            if (!carParkLocationDTO.getLat().equals(thirdJtParkSyncDTO.getConvertLat())) {
                log.info("carParkLocation,lat: {},thirdJtParkSync,lat: {}", carParkLocationDTO.getLat(), thirdJtParkSyncDTO.getConvertLat());
                isUpdate = true;
                carParkLocationDTO.setLat(thirdJtParkSyncDTO.getConvertLat());
            }
            if (!carParkLocationDTO.getLng().equals(thirdJtParkSyncDTO.getConvertLng())) {
                log.info("carParkLocation,lng: {},thirdJtParkSync,lng: {}", carParkLocationDTO.getLng(), thirdJtParkSyncDTO.getConvertLng());
                isUpdate = true;
                carParkLocationDTO.setLng(thirdJtParkSyncDTO.getConvertLng());
            }
            if (!carParkLocationDTO.getAddress().equals(thirdJtParkSyncDTO.getAddress())) {
                isUpdate = true;
                carParkLocationDTO.setAddress(thirdJtParkSyncDTO.getAddress());
            }
            if (isUpdate) {
                carParkLocationService.update(carParkLocationDTO);
            }
        }
        carParkLocationDTO.freeData();
    }

    private String getBillRule(ThirdJtParkSyncDTO thirdJtParkSyncDTO) {
        switch (thirdJtParkSyncDTO.getFeeRuleId()) {
            case 47:
            case 48:
            case 49:
            case 50:
            case 126:
                return CarParkBillRuleEnum.BILL_RULE5.getCode();
            default:
                log.error("不支持的feeRuleId: {}", thirdJtParkSyncDTO.getFeeRuleId());
                return null;
        }
    }

    /**
     * 保存
     *
     * @param dto 页面对象
     * @return 页面对象
     */
    @Transactional(rollbackFor = Exception.class)
    public ThirdJtParkSyncDTO save(ThirdJtParkSyncDTO dto) {
        final ThirdJtParkSync model = dtoToModel(dto);
        try {
            if (super.save(model)) {
                return modelToDto(model);
            }
            throw new ApiException("添加失败");
        } finally {
            clearCache(model);
            model.freeData();
        }
    }

    /**
     * 修改
     *
     * @param dto 页面对象
     */
    @Transactional(rollbackFor = Exception.class)
    public void update(ThirdJtParkSyncDTO dto) {
        final ThirdJtParkSync historyModel = Optional.ofNullable(getById(dto.getParkNo())).orElseThrow(() -> new ApiException("ID不存在,不能更新"));
        final ThirdJtParkSync model = dtoToModel(dto);
        try {
            if (Boolean.FALSE.equals(isExistsById(model.getParkNo()))) {
                throw new ApiException("ID不存在,不能更新");
            }

            if (!super.updateById(model)) {
                throw new ApiException("更新失败");
            }
        } finally {
            clearCache(historyModel);
            historyModel.freeData();
            model.freeData();
        }
    }

    /**
     * 批量添加
     *
     * @param mList 数据库对象
     */
    @Transactional(rollbackFor = Exception.class)
    public void saveBatch(List<ThirdJtParkSync> mList) throws ApiException {
        try {
            if (!super.saveBatch(mList)) {
                throw new ApiException("批量添加失败");
            }
        } finally {
            clearCaches(mList);
        }
    }

    /**
     * 批量更新
     *
     * @param mList 数据库对象
     */
    @Transactional(rollbackFor = Exception.class)
    public void updateBatchIds(List<ThirdJtParkSync> mList) {
        final List<String> ids = mList.stream().map(ThirdJtParkSync::getParkNo).collect(toList());
        final List<ThirdJtParkSync> historyModelList = checkIds(ids);
        try {
            if (!super.updateBatchById(mList)) {
                throw new ApiException("批量更新失败");
            }
        } finally {
            clearCaches(historyModelList);
            historyModelList.clear();
            ids.clear();
        }
    }

    /**
     * 根据传入对象构建查询参数，判断是否存在
     *
     * @param dto 参数
     * @return 存在为true
     */
    @Transactional(readOnly = true)
    public Boolean isExists(ThirdJtParkSyncDTO dto) {
        final QueryWrapper<ThirdJtParkSync> queryWrapper = createQueryWrapper(dto);
        final boolean exists = super.count(queryWrapper) > 0;
        queryWrapper.clear();
        return exists;
    }

    /**
     * 根据主键判断数据是否存在
     *
     * @param parkNo 主键
     * @return 存在为true
     */
    @Transactional(readOnly = true)
    public Boolean isExistsById(String parkNo) {
        boolean exists = false;
        if (StringUtils.hasLength(parkNo)) {
            final ThirdJtParkSync model = getById(parkNo);
            exists = (null != model);
            if (exists) {
                model.freeData();
            }
        }
        return exists;
    }

    /**
     * 根据主键获取数据
     *
     * @param parkNo 主键
     * @return 单条记录
     */
    @Transactional(readOnly = true)
    public ThirdJtParkSync getById(String parkNo) {
        final String key = RedisTemplateUtil.getRedisCacheKey(PREFIX_ID, parkNo);
        return redisTemplateUtil.get(new CacheKey().setKey(key).setTimeout(ConstantDto.REDIS_TIME_OUT_DAY), () -> super.getById(parkNo), ThirdJtParkSync.class);
    }

    /**
     * 根据主键获取数据
     *
     * @param parkNo 主键
     * @return 单条记录，转换成页面对象
     */
    @Transactional(readOnly = true)
    public ThirdJtParkSyncDTO getByIdDto(String parkNo) {
        return Optional.ofNullable(getById(parkNo)).map(this::modelToDto).orElse(null);
    }

    /**
     * 根据条件查询单条数据
     *
     * @param dto 查询参数
     * @return 单条记录
     */
    @Transactional(readOnly = true)
    public ThirdJtParkSync getOne(ThirdJtParkSyncDTO dto) {
        final QueryWrapper<ThirdJtParkSync> queryWrapper = createQueryWrapper(dto);
        ThirdJtParkSync model = super.getOne(queryWrapper);
        queryWrapper.clear();
        return model;
    }

    /**
     * 根据条件查询单条数据
     *
     * @param dto 查询参数
     * @return 单条记录，转换成页面对象
     */
    @Transactional(readOnly = true)
    public ThirdJtParkSyncDTO getOneDto(ThirdJtParkSyncDTO dto) {
        return Optional.ofNullable(getOne(dto)).map(this::modelToDto).orElse(null);
    }

    /**
     * 根据条件查询列表数据
     *
     * @param dto 查询参数
     * @return 列表数据
     */
    @Transactional(readOnly = true)
    public List<ThirdJtParkSync> getList(ThirdJtParkSyncDTO dto) {
        final QueryWrapper<ThirdJtParkSync> queryWrapper = createQueryWrapper(dto);
        final List<ThirdJtParkSync> list = super.list(queryWrapper);
        queryWrapper.clear();
        return list;
    }

    /**
     * 根据条件查询列表数据
     *
     * @param dto 查询参数
     * @return 列表数据，转换成页面对象
     */
    @Transactional(readOnly = true)
    public List<ThirdJtParkSyncDTO> getListDto(ThirdJtParkSyncDTO dto) {
        return modelToDtoList(getList(dto));
    }

    /**
     * 分页数据
     *
     * @param page 分页对象
     * @param dto  查询参数
     * @return 分页信息
     */
    @Transactional(readOnly = true)
    public IPage<ThirdJtParkSyncDTO> page(Page<ThirdJtParkSync> page, ThirdJtParkSyncDTO dto) {
        final QueryWrapper<ThirdJtParkSync> queryWrapper = createQueryWrapper(dto, "thi.");
        final IPage<ThirdJtParkSyncDTO> iPage = baseMapper.page(page, queryWrapper);
        queryWrapper.clear();
        return iPage;
    }

    /**
     * 清空缓存
     *
     * @param model 数据库对象
     */
    public void clearCache(ThirdJtParkSync model) {
        if (null == model) {
            return;
        }
        String key = RedisTemplateUtil.getRedisCacheKey(PREFIX_ID, model.getParkNo());
        redisTemplateUtil.deleteByKey(key);
    }

    /**
     * 批量清空缓存
     *
     * @param list 数据库对象
     */
    public void clearCaches(List<ThirdJtParkSync> list) {
        if (null == list || list.isEmpty()) {
            return;
        }
        List<String> ids = list.stream().map(model -> RedisTemplateUtil.getRedisCacheKey(PREFIX_ID, model.getParkNo())).collect(toList());
        if (!ids.isEmpty()) {
            redisTemplateUtil.deleteByKey(ids);
            ids.clear();
        }
    }


    /**
     * 数据库对象转页面对象
     *
     * @param model 数据库对象
     * @return 页面对象
     */
    public ThirdJtParkSyncDTO modelToDto(ThirdJtParkSync model) {
        if (null == model) {
            return null;
        }
        final ThirdJtParkSyncDTO dto = new ThirdJtParkSyncDTO();
        dto.setParkNo(model.getParkNo());
        dto.setName(model.getName());
        dto.setAddress(model.getAddress());
        dto.setLng(model.getLng());
        dto.setLat(model.getLat());
        dto.setConvertLat(model.getConvertLat());
        dto.setConvertLng(model.getConvertLng());
        dto.setTotal(model.getTotal());
        dto.setFreeStatus(model.getFreeStatus());
        dto.setServiceStart(model.getServiceStart().format(DateTimeFormatter.ISO_TIME));
        dto.setServiceEnd(model.getServiceEnd().format(DateTimeFormatter.ISO_TIME));
        dto.setFeeRuleId(model.getFeeRuleId());
        dto.setAddTime(model.getAddTime());
        dto.setUpdateTime(model.getUpdateTime());
        buildDisplay(dto);
        return dto;
    }

    /**
     * 页面对象转数据库对象
     *
     * @param dto 页面对象
     * @return 数据库对象
     */
    public ThirdJtParkSync dtoToModel(ThirdJtParkSyncDTO dto) {
        if (null == dto) {
            return null;
        }
        final ThirdJtParkSync model = new ThirdJtParkSync();
        model.setParkNo(dto.getParkNo());
        model.setName(dto.getName());
        model.setAddress(dto.getAddress());
        model.setLng(dto.getLng());
        model.setLat(dto.getLat());
        model.setConvertLat(dto.getConvertLat());
        model.setConvertLng(dto.getConvertLng());
        model.setTotal(dto.getTotal());
        model.setFreeStatus(dto.getFreeStatus());
        model.setServiceStart(LocalTime.parse(dto.getServiceStart(), DateTimeFormatter.ISO_TIME));
        model.setServiceEnd(LocalTime.parse(dto.getServiceEnd(), DateTimeFormatter.ISO_TIME));
        model.setFeeRuleId(dto.getFeeRuleId());
        model.setAddTime(dto.getAddTime());
        model.setUpdateTime(dto.getUpdateTime());
        return model;
    }

    /**
     * 码表转换
     *
     * @param dto 页面对象
     */
    public void buildDisplay(ThirdJtParkSyncDTO dto) {

    }

    /**
     * 数据库对象转页面对象
     *
     * @param list 数据库对象
     * @return 页面对象
     */
    public List<ThirdJtParkSyncDTO> modelToDtoList(List<ThirdJtParkSync> list) {
        return Optional.ofNullable(list).orElse(Collections.emptyList()).stream().map(this::modelToDto).collect(toList());
    }

    /**
     * 页面对象转数据库对象
     *
     * @param list 页面对象
     * @return 数据库对象
     */
    public List<ThirdJtParkSync> dtoToModelList(List<ThirdJtParkSyncDTO> list) {
        return Optional.ofNullable(list).orElse(Collections.emptyList()).stream().map(this::dtoToModel).collect(toList());
    }

    /**
     * 拼装查询参数，除了主键的其他字段会自动加入进来
     *
     * @param dto 查询参数，不为空的属性会被自动加入
     */
    public QueryWrapper<ThirdJtParkSync> createQueryWrapper(ThirdJtParkSyncDTO dto) {
        return createQueryWrapper(dto, "");
    }

    /**
     * 拼装查询参数，除了主键的其他字段会自动加入进来
     *
     * @param dto        查询参数，不为空的属性会被自动加入
     * @param tableAlias 表别名
     */
    public QueryWrapper<ThirdJtParkSync> createQueryWrapper(ThirdJtParkSyncDTO dto, String tableAlias) {
        final QueryWrapper<ThirdJtParkSync> queryWrapper = new QueryWrapper<>();
        if (null != dto) {
            if (StringUtils.hasLength(tableAlias)) {
                if (tableAlias.charAt(tableAlias.length() - 1) != '.') {
                    tableAlias += ".";
                }
            }
            if (StringUtils.hasLength(dto.getName())) {
                queryWrapper.eq(tableAlias + "name", dto.getName());
            }
            if (StringUtils.hasLength(dto.getAddress())) {
                queryWrapper.eq(tableAlias + "address", dto.getAddress());
            }
            if (StringUtils.hasLength(dto.getFreeStatus())) {
                queryWrapper.eq(tableAlias + "free_status", dto.getFreeStatus());
            }
        }
        return queryWrapper;
    }

    /**
     * 批量检查主键在数据库中是否存在
     *
     * @param ids 主键集合
     */
    public List<ThirdJtParkSync> checkIds(List<String> ids) {
        if (null == ids || ids.isEmpty()) {
            throw new ApiException("ids不能为空");
        }
        final List<ThirdJtParkSync> list = super.listByIds(ids);
        if (list.isEmpty()) {
            throw new ApiException("ids不存在" + Arrays.toString(ids.toArray()));
        }
        if (ids.size() == list.size()) {
            return list;
        }
        List<String> dbIds = list.stream().map(ThirdJtParkSync::getParkNo).collect(toList());
        final List<String> notExistsList = ids.stream().filter(id -> !dbIds.contains(id)).collect(toList());
        dbIds.clear();
        if (!notExistsList.isEmpty()) {
            throw new ApiException("ids不存在" + Arrays.toString(notExistsList.toArray()));
        }
        return list;
    }

    @Transactional(rollbackFor = Exception.class)
    public void buildAddOrUpdate(List<ThirdJtParkSyncDTO> list, List<ThirdJtParkSync> addList, List<ThirdJtParkSync> updateList) {
        final LocalDateTime now = LocalDateTime.now();
        list.forEach(thirdJtParkSyncDTO -> {
            ThirdJtParkSync history = getById(thirdJtParkSyncDTO.getParkNo());
            if (null == history) {
                thirdJtParkSyncDTO.setAddTime(now);
                buildConvert(thirdJtParkSyncDTO);
                addList.add(dtoToModel(thirdJtParkSyncDTO));
            } else {
                if (!Objects.equals(thirdJtParkSyncDTO.getLat(), history.getLat()) || !Objects.equals(thirdJtParkSyncDTO.getLng(), history.getLng())) {
                    thirdJtParkSyncDTO.setConvert(true);
                }
                if (null == history.getConvertLat() || null == history.getConvertLng()) {
                    thirdJtParkSyncDTO.setConvert(true);
                }
                if (thirdJtParkSyncDTO.isConvert()) {
                    buildConvert(thirdJtParkSyncDTO);
                }else{
                    //不需要转换
                    thirdJtParkSyncDTO.setConvertLat(history.getConvertLat());
                    thirdJtParkSyncDTO.setConvertLng(history.getConvertLng());
                }
                if (isUpdate(thirdJtParkSyncDTO, history)) {
                    thirdJtParkSyncDTO.setUpdateTime(now);
                    updateList.add(dtoToModel(thirdJtParkSyncDTO));
                }
            }

        });
    }

    private static void buildConvert(ThirdJtParkSyncDTO thirdJtParkSyncDTO) {
        GeoPointDTO geoPointDTO = GeoUtil.convertBD09ToGCJ02(thirdJtParkSyncDTO.getLat().doubleValue(), thirdJtParkSyncDTO.getLng().doubleValue());
        thirdJtParkSyncDTO.setConvertLat(geoPointDTO.getLat());
        thirdJtParkSyncDTO.setConvertLng(geoPointDTO.getLng());
    }

    private boolean isUpdate(ThirdJtParkSyncDTO dto, ThirdJtParkSync model) {
        if (!dto.getLat().equals(model.getLat())) {
            return true;
        }
        if (!dto.getLng().equals(model.getLng())) {
            return true;
        }
        if (!dto.getAddress().equals(model.getAddress())) {
            return true;
        }
        if (!dto.getFeeRuleId().equals(model.getFeeRuleId())) {
            return true;
        }
        if (!dto.getName().equals(model.getName())) {
            return true;
        }
        if (!dto.getServiceEnd().equals(model.getServiceEnd().format(DateTimeFormatter.ISO_TIME))) {
            return true;
        }
        if (!dto.getServiceStart().equals(model.getServiceStart().format(DateTimeFormatter.ISO_TIME))) {
            return true;
        }
        if (!dto.getTotal().equals(model.getTotal())) {
            return true;
        }
        if (null == model.getConvertLng()) {
            return true;
        }
        return null == model.getConvertLat();
    }

//    public void build(List<GeoPoint> covertList, Map<Integer, ThirdJtParkSyncDTO> map) {
//        for (int j = 0; j < covertList.size(); j++) {
//            GeoPoint newLocation = covertList.get(j);
//            GeoPointDTO geoPointDTO = GeoUtil.convertBD09ToGCJ02(newLocation.getLat().doubleValue(), newLocation.getLng().doubleValue());
//            ThirdJtParkSyncDTO thirdJtParkSyncDTO = map.get(j);
//            thirdJtParkSyncDTO.setConvertLat(geoPointDTO.getLat());
//            thirdJtParkSyncDTO.setConvertLng(geoPointDTO.getLng());
//        }
////        List<GeoPoint> translates = tencentLocationService.translates(covertList);
////        for (int j = 0; j < translates.size(); j++) {
////            GeoPoint newLocation = translates.get(j);
////            ThirdJtParkSyncDTO thirdJtParkSyncDTO = map.get(j);
////            thirdJtParkSyncDTO.setConvertLat(newLocation.getLat());
////            thirdJtParkSyncDTO.setConvertLng(newLocation.getLng());
////        }
//    }
}